package com.ziroom.crm.mq.core.processor;

import com.ziroom.crm.mq.core.MqType;
import com.ziroom.crm.mq.core.retry.RetryContext;

import java.util.function.Consumer;

/**
 * <p></p>
 * <p>
 * <PRE>
 * <BR>    修改记录
 * <BR>-----------------------------------------------
 * <BR>    修改日期         修改人          修改内容
 * </PRE>
 *
 * @author WeiShaoying
 * @version 1.0
 * @date Created in 2020年09月02日 10:22
 * @since 1.0
 */
public class QueueWrapper {

    /**
     * 队列名称
     */
    protected final String name;

    /**
     * 队列类型
     */
    protected final MqType mqType;

    /**
     * 重试消费 函数
     */
    protected Consumer<RetryContext> retryCallback;


    public QueueWrapper(String name, MqType mqType) {
        this.name = name;
        this.mqType = mqType;
    }

    public QueueWrapper(String name, MqType mqType, Consumer<RetryContext> retryCallback) {
        this(name, mqType);
        this.retryCallback = retryCallback;
    }

    public String getName() {
        return name;
    }

    public MqType getMqType() {
        return mqType;
    }

    public Consumer<RetryContext> getRetryCallback() {
        return retryCallback;
    }

    public void setRetryCallback(Consumer<RetryContext> retryCallback) {
        this.retryCallback = retryCallback;
    }

    /**
     * Only {@link #getName()} is considered.
     */
    @Override
    public int hashCode() {
        return getName().hashCode();
    }

    /**
     * Only {@link #getName()} is considered.
     */
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof QueueWrapper) {
            QueueWrapper rw = (QueueWrapper) obj;
            return rw.getName().equals(getName());
        }
        return false;
    }
}
